#' ---
#' title: "Descriptive Representation and Public Support for Supreme Court Nominees"
#' author: "Jaclyn Kaslovsky, Jon Rogowski, and Andrew Stone"
#' ---

library(cjoint); library(gridExtra)

load("article_data.RData")

##############################################################
# Table 1: Descriptive Statistics of the Dependent Variables #
##############################################################
# Support
mean(data$support2, na.rm=T)
sd(data$support2, na.rm=T)

# Qualifications
mean(data$qualified2, na.rm=T)
sd(data$qualified2, na.rm=T)

# Trust
mean(data$trust2, na.rm=T)
sd(data$trust2, na.rm=T)

#################################################################################
# Figure 1: Effect of Shared Descriptive Characteristics on Nominee Evaluations #
#################################################################################
# Subset dataset to respondents who answered the support question  
data.support <- data[!(is.na(data$support) | data$support==""), ]

# Define variables to pass into model
data.support$politicized <- as.factor(data.support$politicized)
data.support$treat_age <- as.factor(data.support$treat_age)
data.support$treat_gender <- as.factor(data.support$treat_gender)
data.support$treat_race <- as.factor(data.support$treat_race)
data.support$treat_lawS <- as.factor(data.support$treat_lawS)
data.support$treat_currentP <- as.factor(data.support$treat_currentP)
data.support$treat_pAbortion <- as.factor(data.support$treat_pAbortion)

# Estimate the AMCEs, cluster SEs by respondent
results.support.overall <- amce(support2 ~ politicized + treat_age + treat_gender + treat_race +  treat_lawS + treat_currentP + treat_pAbortion + same.gender + 
                                  same.race, data=data.support,cluster=TRUE, respondent.id="caseid", weights="weight")
summary(results.support.overall)

# Subset dataset to respondents who answered the qualified question  
data.qualified <- data[!(is.na(data$qualified) | data$qualified==""), ]

# Define variables to pass into model
data.qualified$politicized <- as.factor(data.qualified$politicized)
data.qualified$treat_age <- as.factor(data.qualified$treat_age)
data.qualified$treat_gender <- as.factor(data.qualified$treat_gender)
data.qualified$treat_race <- as.factor(data.qualified$treat_race)
data.qualified$treat_lawS <- as.factor(data.qualified$treat_lawS)
data.qualified$treat_currentP <- as.factor(data.qualified$treat_currentP)
data.qualified$treat_pAbortion <- as.factor(data.qualified$treat_pAbortion)

# Estimate the AMCEs, cluster SEs by respondent
results.qualified.overall <- amce(qualified2 ~ politicized + treat_age + treat_gender + treat_race +  treat_lawS + treat_currentP + treat_pAbortion + same.gender + 
                                    same.race, data=data.qualified,cluster=TRUE, respondent.id="caseid",weights="weight")
summary(results.qualified.overall)

# Subset dataset to respondents who answered the trust question  
data.trust <- data[!(is.na(data$trust) | data$trust==""), ]

# Define variables to pass into model
data.trust$politicized <- as.factor(data.trust$politicized)
data.trust$treat_age <- as.factor(data.trust$treat_age)
data.trust$treat_gender <- as.factor(data.trust$treat_gender)
data.trust$treat_race <- as.factor(data.trust$treat_race)
data.trust$treat_lawS <- as.factor(data.trust$treat_lawS)
data.trust$treat_currentP <- as.factor(data.trust$treat_currentP)
data.trust$treat_pAbortion <- as.factor(data.trust$treat_pAbortion)

# Estimate the AMCEs, cluster SEs by respondent
results.trust.overall <- amce(trust2 ~ politicized + treat_age + treat_gender + treat_race +  treat_lawS + treat_currentP + treat_pAbortion + same.gender + 
                                same.race, data=data.trust,cluster=TRUE, respondent.id="caseid", weights="weight")
summary(results.trust.overall)

# Coefficients and SEs for support
# Make a coefficient plot
coef_gender_support <-0.01267180
coef_race_support <-0.06145415

se_gender_support <-0.012395 
se_race_support <- 0.017882

# Create the confidence intervals
z_95 <- qnorm(.975)
ci_1_support <- c(coef_gender_support - z_95*se_gender_support, coef_gender_support + z_95*se_gender_support)
ci_2_support <- c(coef_race_support - z_95*se_race_support, coef_race_support + z_95*se_race_support)

# Data frames for plotting
gender_support <- data.frame(est = coef_gender_support, lb = ci_1_support[1], ub = ci_1_support[2], model = "Support")
race_support <- data.frame(est = coef_race_support, lb = ci_2_support[1], ub = ci_2_support[2], model = "Support")

# Coefficients and SEs for qualified
coef_gender_qualified <- 0.0032480
coef_race_qualified <-0.0452344

se_gender_qualified <- 0.013705
se_race_qualified <- 0.019436

# Create the confidence intervals
z_95 <- qnorm(.975)
ci_1_qualified <- c(coef_gender_qualified - z_95*se_gender_qualified, coef_gender_qualified + z_95*se_gender_qualified)
ci_2_qualified  <- c(coef_race_qualified - z_95*se_race_qualified, coef_race_qualified + z_95*se_race_qualified)

# Data frames for plotting
gender_qualified <- data.frame(est = coef_gender_qualified, lb = ci_1_qualified [1], ub = ci_1_qualified [2], model = "Qualified")
race_qualified <- data.frame(est = coef_race_qualified, lb = ci_2_qualified [1], ub = ci_2_qualified [2], model = "Qualified")

# Coefficients and SEs for trust
coef_gender_trust <-0.0249145
coef_race_trust <-0.0622936

se_gender_trust <-0.012216
se_race_trust <- 0.020010

# Create the confidence intervals
z_95 <- qnorm(.975)
ci_1_trust <- c(coef_gender_trust - z_95*se_gender_trust, coef_gender_trust + z_95*se_gender_trust)
ci_2_trust <- c(coef_race_trust - z_95*se_race_trust, coef_race_trust + z_95*se_race_trust)

# Data frames for plotting
gender_trust <- data.frame(est = coef_gender_trust, lb = ci_1_trust[1], ub = ci_1_trust[2], model = "Trust")
race_trust <- data.frame(est = coef_race_trust, lb = ci_2_trust[1], ub = ci_2_trust[2], model = "Trust")

# Make the plot
dat <- as.data.frame(c("Qualified","Trust","Support"))
colnames(dat) <- c("order")

# Race
p1 <- ggplot(race_trust, aes(x = model, y = est)) +
  geom_point() +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2) +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("Coefficient Estimate") + 
  geom_point(data= race_qualified, aes(x = model, y = est)) +
  geom_errorbar(data=race_qualified, aes(ymin = lb, ymax = ub), width = 0.2) +
  geom_point(data= race_support, aes(x = model, y = est)) +
  geom_errorbar(data=race_support, aes(ymin = lb, ymax = ub), width = 0.2) +
  theme_bw() + coord_flip() + labs(title="Race")  + ylim(-.1,0.2) + scale_x_discrete(limits=dat$order) +
  theme(plot.title = element_text(hjust = 0.5))

# Gender
p2 <-ggplot(gender_trust, aes(x = model, y = est)) +
  geom_point() +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2) +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("Coefficient Estimate") + 
  geom_point(data= gender_qualified, aes(x = model, y = est)) +
  geom_errorbar(data=gender_qualified, aes(ymin = lb, ymax = ub), width = 0.2) +
  geom_point(data= gender_support, aes(x = model, y = est)) +
  geom_errorbar(data=gender_support, aes(ymin = lb, ymax = ub), width = 0.2) +
  theme_bw() + coord_flip() + labs(title="Gender")  + ylim(-.1,0.2) + scale_x_discrete(limits=dat$order) +
  theme(plot.title = element_text(hjust = 0.5))

grid.arrange(p1, p2, ncol=2)

#####################################################
# Figure 2: Partisanship, Race, and Nominee Support #
#####################################################
# Support estimates, white respondents
# Re-level the data to treat respondent's race/gender as the baseline for nominee evaluations
data.support <- within(data.support, race_nominee <- relevel(race_nominee, ref = "White"))
data.support <- within(data.support, gender_nominee <- relevel(gender_nominee, ref = "Male"))

# Subset support dataset to white respondents
data.support.white <- data.support[which(data.support$race_respondent == "White"),]

# Analysis for Democrats only
data.support.white.dems <- data.support.white[which(data.support.white$pid3a == "Democrat"),]
results.support.white.dems <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                   data=data.support.white.dems,cluster=TRUE,
                                   respondent.id="caseid",weights="weight")

# Analysis for Republicans only
data.support.white.reps <- data.support.white[which(data.support.white$pid3a == "Republican"),]
results.support.white.reps <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age +  treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                   data=data.support.white.reps,cluster=TRUE,
                                   respondent.id="caseid",weights="weight")

# Support estimates, Black respondents
# Re-level the data to treat respondent's race as the baseline for nominee evaluations  
data.support <- within(data.support, race_nominee <- relevel(race_nominee, ref = "Black"))

# Subset support dataset to Black respondents
data.support.black <- data.support[which(data.support$race_respondent == "Black"),]

# Analysis for Democrats only
data.support.black.dems <- data.support.black[which(data.support.black$pid3a == "Democrat"),]
results.support.black.dems <- amce(support2 ~ gender_nominee + race_nominee +  politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                   data=data.support.black.dems,cluster=TRUE,
                                   respondent.id="caseid",weights="weight")

# Analysis for Republicans only
data.support.black.reps <- data.support.black[which(data.support.black$pid3a == "Republican"),]
results.support.black.reps <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                   data=data.support.black.reps,cluster=TRUE,
                                   respondent.id="caseid",weights="weight")

# Support estimates, Hispanic respondents
# Re-level the data to treat respondent's race as the baseline for nominee evaluations  
data.support <- within(data.support, race_nominee <- relevel(race_nominee, ref = "Hispanic"))

# Subset support dataset to Hispanic respondents
data.support.hispanic <- data.support[which(data.support$race_respondent == "Hispanic"),]

# Analysis for Democrats only
data.support.hispanic.dems <- data.support.hispanic[which(data.support.hispanic$pid3a == "Democrat"),]
results.support.hispanic.dems <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                      data=data.support.hispanic.dems,cluster=TRUE,
                                      respondent.id="caseid",weights="weight")

# Analysis for Republicans only
data.support.hispanic.reps <- data.support.hispanic[which(data.support.hispanic$pid3a == "Republican"),]
results.support.hispanic.reps <- amce(support2 ~ gender_nominee + race_nominee+ politicized + treat_age +  treat_lawS + treat_currentP + treat_pAbortion + same.gender, 
                                      data=data.support.hispanic.reps,cluster=TRUE,
                                      respondent.id="caseid",weights="weight")

# Coefficients and SEs for Democrats (from the models)
# Coefficients
coef.hispanicresp.dem.white <- -0.035620
coef.hispanicresp.dem.black <- 0.062250 

coef.blackresp.dem.hispanic <- -0.1676413
coef.blackresp.dem.white <- -0.2253979

coef.whiteresp.dem.hispanic <- 0.0240293 
coef.whiteresp.dem.black <- 0.0452267

# SEs
se.hispanicresp.dem.white <- 0.084162 
se.hispanicresp.dem.black <- 0.078847 

se.blackresp.dem.hispanic <- 0.056423
se.blackresp.dem.white <- 0.054109

se.whiteresp.dem.hispanic <- 0.027374
se.whiteresp.dem.black <-  0.033561

# Create the confidence intervals
z_95 <- qnorm(.975)
z_90 <- qnorm(.95)
ci_1_d <- c(coef.hispanicresp.dem.white - z_95*se.hispanicresp.dem.white, coef.hispanicresp.dem.white + z_95*se.hispanicresp.dem.white)
ci_2_d <- c(coef.hispanicresp.dem.black - z_95*se.hispanicresp.dem.black, coef.hispanicresp.dem.black + z_95*se.hispanicresp.dem.black)
ci_3_d <- c(coef.blackresp.dem.hispanic - z_95*se.blackresp.dem.hispanic, coef.blackresp.dem.hispanic + z_95*se.blackresp.dem.hispanic)
ci_4_d <- c(coef.blackresp.dem.white - z_95*se.blackresp.dem.white, coef.blackresp.dem.white + z_95*se.blackresp.dem.white)
ci_5_d <- c(coef.whiteresp.dem.hispanic - z_95*se.whiteresp.dem.hispanic, coef.whiteresp.dem.hispanic + z_95*se.whiteresp.dem.hispanic)
ci_6_d <- c(coef.whiteresp.dem.black - z_95*se.whiteresp.dem.black, coef.whiteresp.dem.black + z_95*se.whiteresp.dem.black)

# Data frames for plotting
hispanicresp.dem.white <- data.frame(est = coef.hispanicresp.dem.white, lb = ci_1_d[1], ub = ci_1_d[2], model = "Hispanic-White")
hispanicresp.dem.black <- data.frame(est = coef.hispanicresp.dem.black, lb = ci_2_d[1], ub = ci_2_d[2], model = "Hispanic-Black")
blackresp.dem.hispanic <- data.frame(est = coef.blackresp.dem.hispanic, lb = ci_3_d[1], ub = ci_3_d[2], model = "Black-Hispanic")
blackresp.dem.white <- data.frame(est = coef.blackresp.dem.white, lb = ci_4_d[1], ub = ci_4_d[2], model = "Black-White")
whiteresp.dem.hispanic <- data.frame(est = coef.whiteresp.dem.hispanic, lb = ci_5_d[1], ub = ci_5_d[2], model = "White-Hispanic")
whiteresp.dem.black <- data.frame(est = coef.whiteresp.dem.black, lb = ci_6_d[1], ub = ci_6_d[2], model = "White-Black")

# Coefficients and SEs for Republicans (from the models)
# Coefficients
coef.hispanicresp.rep.white <- -0.1118969 
coef.hispanicresp.rep.black <- 0.2309537 

coef.blackresp.rep.hispanic <- -0.1083411
coef.blackresp.rep.white <- -0.1803492 

coef.whiteresp.rep.hispanic <- -0.0414981 
coef.whiteresp.rep.black <-  -0.0667300

# SEs
se.hispanicresp.rep.white <- 0.087934 
se.hispanicresp.rep.black <- 0.113191 

se.blackresp.rep.hispanic <- 0.25746
se.blackresp.rep.white <- 0.16097 

se.whiteresp.rep.hispanic <- 0.034822
se.whiteresp.rep.black <-  0.029364

# Create the confidence intervals
z_95 <- qnorm(.975)
z_90 <- qnorm(.95)
ci_1_r <- c(coef.hispanicresp.rep.white - z_95*se.hispanicresp.rep.white, coef.hispanicresp.rep.white + z_95*se.hispanicresp.rep.white)
ci_2_r <- c(coef.hispanicresp.rep.black - z_95*se.hispanicresp.rep.black, coef.hispanicresp.rep.black + z_95*se.hispanicresp.rep.black)
ci_3_r <- c(coef.blackresp.rep.hispanic - z_95*se.blackresp.rep.hispanic, coef.blackresp.rep.hispanic + z_95*se.blackresp.rep.hispanic)
ci_4_r <- c(coef.blackresp.rep.white - z_95*se.blackresp.rep.white, coef.blackresp.rep.white + z_95*se.blackresp.rep.white)
ci_5_r <- c(coef.whiteresp.rep.hispanic - z_95*se.whiteresp.rep.hispanic, coef.whiteresp.rep.hispanic + z_95*se.whiteresp.rep.hispanic)
ci_6_r <- c(coef.whiteresp.rep.black - z_95*se.whiteresp.rep.black, coef.whiteresp.rep.black + z_95*se.whiteresp.rep.black)

# Data frames for plotting
hispanicresp.rep.white <- data.frame(est = coef.hispanicresp.rep.white, lb = ci_1_r[1], ub = ci_1_r[2], model = "Hispanic-White")
hispanicresp.rep.black <- data.frame(est = coef.hispanicresp.rep.black, lb = ci_2_r[1], ub = ci_2_r[2], model = "Hispanic-Black")
blackresp.rep.hispanic <- data.frame(est = coef.blackresp.rep.hispanic, lb = ci_3_r[1], ub = ci_3_r[2], model = "Black-Hispanic")
blackresp.rep.white <- data.frame(est = coef.blackresp.rep.white, lb = ci_4_r[1], ub = ci_4_r[2], model = "Black-White")
whiteresp.rep.hispanic <- data.frame(est = coef.whiteresp.rep.hispanic, lb = ci_5_r[1], ub = ci_5_r[2], model = "White-Hispanic")
whiteresp.rep.black <- data.frame(est = coef.whiteresp.rep.black, lb = ci_6_r[1], ub = ci_6_r[2], model = "White-Black")

g3 <- ggplot(hispanicresp.dem.white, aes(x = model, y = est)) +
  geom_point(colour="grey45") +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("") + 
  geom_point(data= hispanicresp.dem.black, aes(x = model, y = est),colour="grey45") +
  geom_errorbar(data=hispanicresp.dem.black, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_point(data= blackresp.dem.hispanic, aes(x = model, y = est),colour="grey70") +
  geom_errorbar(data=blackresp.dem.hispanic, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey70") +
  geom_point(data= blackresp.dem.white, aes(x = model, y = est),colour="grey70") +
  geom_errorbar(data=blackresp.dem.white, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey70")  + 
  geom_point(data= whiteresp.dem.hispanic, aes(x = model, y = est),colour="black") +
  geom_errorbar(data=whiteresp.dem.hispanic, aes(ymin = lb, ymax = ub), width = 0.2, colour="black") +
  geom_point(data= whiteresp.dem.black, aes(x = model, y = est),colour="black") +
  geom_errorbar(data=whiteresp.dem.black, aes(ymin = lb, ymax = ub), width = 0.2, colour="black")  + 
  theme_bw() + coord_flip() + ylim(-.7,0.5) + 
  labs(title="Democrats: Support for Nominees by Race") +
  theme(plot.title = element_text(hjust = 0.5))


g4 <- ggplot(hispanicresp.rep.white, aes(x = model, y = est)) +
  geom_point(colour="grey45") +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("") + 
  geom_point(data= hispanicresp.rep.black, aes(x = model, y = est),colour="grey45") +
  geom_errorbar(data=hispanicresp.rep.black, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_point(data= blackresp.rep.hispanic, aes(x = model, y = est),colour="grey70") +
  geom_errorbar(data=blackresp.rep.hispanic, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey70") +
  geom_point(data= blackresp.rep.white, aes(x = model, y = est),colour="grey70") +
  geom_errorbar(data=blackresp.rep.white, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey70")  + 
  geom_point(data= whiteresp.rep.hispanic, aes(x = model, y = est),colour="black") +
  geom_errorbar(data=whiteresp.rep.hispanic, aes(ymin = lb, ymax = ub), width = 0.2, colour="black") +
  geom_point(data= whiteresp.rep.black, aes(x = model, y = est),colour="black") +
  geom_errorbar(data=whiteresp.rep.black, aes(ymin = lb, ymax = ub), width = 0.2, colour="black")  + 
  theme_bw() + coord_flip()  + ylim(-.7,0.5) + 
  labs(title="Republicans: Support for Nominees by Race") +
  theme(plot.title = element_text(hjust = 0.5))

grid.arrange(g3, g4, ncol=1, left= textGrob("Respondent-Candidate Pairing", rot=90), bottom=textGrob("Coefficient Estimate"))

#######################################################
# Figure 3: Partisanship, Gender, and Nominee Support #
#######################################################
# Support, male respondents
# Re-level the data to treat respondent's gender as the baseline for nominee evaluations  
data.support <- within(data.support, gender_nominee <- relevel(gender_nominee, ref = "Male"))

data.support.male <- data.support[which(data.support$gender_respondent == "Male"),]

# Democrats only
data.support.male.dems <- data.support.male[which(data.support.male$pid3a == "Democrat"),]
results.support.male.dems <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.race, 
                                  data=data.support.male.dems,cluster=TRUE,
                                  respondent.id="caseid",weights="weight")

# Republicans only
data.support.male.reps <- data.support.male[which(data.support.male$pid3a == "Republican"),]
results.support.male.reps <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age +  treat_lawS + treat_currentP + treat_pAbortion + same.race, 
                                  data=data.support.male.reps,cluster=TRUE,
                                  respondent.id="caseid",weights="weight")

# Support estimates, Female respondents
# Re-level the data to treat respondent's gender as the baseline for nominee evaluations  
data.support <- within(data.support, gender_nominee <- relevel(gender_nominee, ref = "Female"))

data.support.female <- data.support[which(data.support$gender_respondent == "Female"),]

# Democrats only
data.support.female.dems <- data.support.female[which(data.support.female$pid3a == "Democrat"),]
results.support.female.dems <- amce(support2 ~ gender_nominee + race_nominee +  politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.race, 
                                    data=data.support.female.dems,cluster=TRUE,
                                    respondent.id="caseid",weights="weight")

# Republicans only
data.support.female.reps <- data.support.female[which(data.support.female$pid3a == "Republican"),]
results.support.female.reps <- amce(support2 ~ gender_nominee + race_nominee + politicized + treat_age + treat_lawS + treat_currentP + treat_pAbortion + same.race, 
                                    data=data.support.female.reps,cluster=TRUE,
                                    respondent.id="caseid",weights="weight")

# Coefficients and SEs for Democrats (from the models)
# Coefficients
coef.malesresp.dem.female <- -0.035258 
coef.femalesresp.dem.male <- -0.0204403

# SEs
se.malesresp.dem.female <- 0.033223 
se.femalesresp.dem.male <- 0.028237

# Create the confidence intervals
z_95 <- qnorm(.975)
z_90 <- qnorm(.95)
ci_1_gender_d <- c(coef.malesresp.dem.female - z_95*se.malesresp.dem.female, coef.malesresp.dem.female + z_95*se.malesresp.dem.female)
ci_2_gender_d <- c(coef.femalesresp.dem.male - z_95*se.femalesresp.dem.male, coef.femalesresp.dem.male + z_95*se.femalesresp.dem.male)

# Data frames for plotting
maleresp.dem.female <- data.frame(est = coef.malesresp.dem.female, lb = ci_1_gender_d[1], ub = ci_1_gender_d[2], model = "Male-Female")
femaleresp.dem.male <- data.frame(est = coef.femalesresp.dem.male, lb = ci_2_gender_d[1], ub = ci_2_gender_d[2], model = "Female-Male")

# Coefficients and SEs for Republicans (from the models)
# Coefficients
coef.malesresp.rep.female <- -0.029411 
coef.femalesresp.rep.male <- 0.0052506 

# SEs
se.malesresp.rep.female <- 0.032672 
se.femalesresp.rep.male <- 0.027262 

# Create the confidence intervals
z_95 <- qnorm(.975)
z_90 <- qnorm(.95)
ci_1_gender_r <- c(coef.malesresp.rep.female - z_95*se.malesresp.rep.female, coef.malesresp.rep.female + z_95*se.malesresp.rep.female)
ci_2_gender_r <- c(coef.femalesresp.rep.male - z_95*se.femalesresp.rep.male, coef.femalesresp.rep.male + z_95*se.femalesresp.rep.male)

# Data frames for plotting
maleresp.rep.female <- data.frame(est = coef.malesresp.dem.female, lb = ci_1_gender_r[1], ub = ci_1_gender_r[2], model = "Male-Female")
femaleresp.rep.male <- data.frame(est = coef.femalesresp.rep.male, lb = ci_2_gender_r[1], ub = ci_2_gender_r[2], model = "Female-Male")

g5 <- ggplot(maleresp.dem.female, aes(x = model, y = est)) +
  geom_point(colour="grey45") +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("") + 
  geom_point(data= femaleresp.dem.male, aes(x = model, y = est),colour="grey45") +
  geom_errorbar(data=femaleresp.dem.male, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  theme_bw() + coord_flip() + ylim(-.25,0.25) + 
  labs(title="Democrats: Support for Nominees by Gender") +
  theme(plot.title = element_text(hjust = 0.5))


g6 <- ggplot(maleresp.rep.female, aes(x = model, y = est)) +
  geom_point(colour="grey45") +
  geom_errorbar(aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  geom_hline(yintercept = 0, lty = 2) +
  xlab("") +
  ylab("") + 
  geom_point(data= femaleresp.rep.male, aes(x = model, y = est),colour="grey45") +
  geom_errorbar(data=femaleresp.rep.male, aes(ymin = lb, ymax = ub), width = 0.2, colour="grey45") +
  theme_bw() + coord_flip() + ylim(-.25,0.25) + 
  labs(title="Republicans: Support for Nominees by Gender") +
  theme(plot.title = element_text(hjust = 0.5))

grid.arrange(g5, g6, ncol=1, left= textGrob("Respondent-Candidate Pairing", rot=90), bottom=textGrob("Coefficient Estimate"))
